﻿using System;
using System.Windows;
using System.Windows.Media;
using MaxStoreErp.Core.BaseClasses;
using MaxStoreErp.Core.Commands;
using MaxStoreErp.Core.Interfaces;
using MaxStoreErp.Core.Ui.MainMenu;
using MaxStoreShop.Core.Interception;
using MaxStoreShop.Dal.Repositories.Directories;
using MaxStoreShop.Logic.RepositoriesContracts.Directories;
using MaxStoreShop.Logic.Services.Directories;
using MaxStoreShop.Logic.ServicesContracts.Directories;
using Microsoft.Practices.Prism.Modularity;
using Microsoft.Practices.Unity;

namespace MaxStoreShop.WarehouseModule
{
    [Module(ModuleName = "MaxStoreShop.WarehouseModule")]
    [ModuleDependency("MaxStoreShop.CoreModule")]
    public class WarehouseModule : ModuleBase
    {
        protected override string ModuleName
        {
            get { return "Склад"; }
        }

        protected override void RegisterServices()
        {
            base.RegisterServices();
            UnityContainer.RegisterType<IMeasureTypeRepository, MeasureTypeRepository>()
                .RegisterType<IProductCategoryRepository, ProductCategoryRepository>()
                .RegisterType<ICharacterRepository, CharacterRepository>()
                .RegisterType<IMeasureTypeService, MeasureTypeService>()
                .RegisterType<IProductCategoryService, ProductCategoryService>()
                .RegisterType<ICharacterService, CharacterService>()
                .RegisterType<IStorageLocationRepository, StorageLocationRepository>()
                .RegisterType<IStorageLocationService, StorageLocationService>()
                .RegisterType<ISupplierRepository, SupplierRepository>()
                .RegisterType<ISupplierService, SupplierService>();
            UnityContainer.RegisterType<ICharacterEditor, Characters.CharacterEditor.CharacterEditorPresenter>();
        }

        protected override void RegisterMenuItems()
        {
            base.RegisterMenuItems();
            var icons = new ResourceDictionary
            {
                Source = new Uri("/MaxStoreShop.Media;component/Icons.xaml", UriKind.RelativeOrAbsolute)
            };
            MainMenuService.Add(new MenuItemControl
            {
                TileCaption = "Виды измерений",
                GroupName = "Справочники",
                IconData = icons["MeasureTypeIcon"] as Geometry,
                Command =
                    new RelayCommand(() => UnityContainer.Resolve<IDocumentManager>().NavigateTo<MeasureTypes.MeasureTypesPresenter>())
            });
            MainMenuService.Add(new MenuItemControl
            {
                TileCaption = "Категории продуктов",
                GroupName = "Справочники",
                IconData = icons["ProductCategoriesIcon"] as Geometry,
                Command =
                    new RelayCommand(() => UnityContainer.Resolve<IDocumentManager>().NavigateTo<ProductCategories.ProductCategoriesPresenter>())
            });
            MainMenuService.Add(new MenuItemControl
            {
                TileCaption = "Люди",
                GroupName = "Справочники",
                IconData = icons["CharactersIcon"] as Geometry,
                Command =
                    new RelayCommand(() => UnityContainer.Resolve<IDocumentManager>().NavigateTo<Characters.CharactersPresenter>())
            });
            MainMenuService.Add(new MenuItemControl
            {
                TileCaption = "Места хранения",
                GroupName = "Справочники",
                IconData = icons["StorageLocationsIcon"] as Geometry,
                Command =
                    new RelayCommand(() => UnityContainer.Resolve<IDocumentManager>().NavigateTo<StorageLocations.StorageLocationsPresenter>())
            });
            MainMenuService.Add(new MenuItemControl
            {
                TileCaption = "Поставщики",
                GroupName = "Справочники",
                IconData = icons["SuppliersIcon"] as Geometry,
                Command =
                    new RelayCommand(() => UnityContainer.Resolve<IDocumentManager>().NavigateTo<Suppliers.SuppliersPresenter>())
            });
        }
    }
}
